---@class IBehaviour : LuaObject
---@field protected super IBehaviour
---@field protected gameObject UnityEngine.GameObject
---@field protected transform UnityEngine.Transform
local this = BaseClass('IBehaviour')

--- 脚本挂载事件 (创建时调用，可用于绑定对象)
---@param obj UnityEngine.GameObject
function this:Awake(obj)
    self.gameObject = obj
    self.transform = obj.transform
end

---@return UnityEngine.Component[]
function this:GetComponents(trans, type)
    local temp = {}
    for i = 1, trans.childCount do
        local tf = trans:GetChild(i - 1)
        local com = tf:GetComponent(typeof(type))
        table.insert(temp, com)
    end
    return temp
end

---@return UnityEngine.Component[]
function this:GetComponentsInChildren(path, type)
    local trans = self:FindTransform(path)
    return self:GetComponents(trans, type)
end

---@return UnityEngine.Component
function this:GetComponent(path, type)
    local t = self:FindTransform(path)
    return t:GetComponent(typeof(type))
end

---@return UnityEngine.GameObject
function this:FindGameObject(path)
    local t = self:FindTransform(path)
    return t.gameObject
end

---@return UnityEngine.Transform
function this:FindTransform(path)
    return self.transform:Find(path)
end

IBehaviour = this